﻿using System;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Framework;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.ControlPanels;
using DotNetNuke.Web.Client.ClientResourceManagement;

namespace BrandonHaynes.Providers.ControlPanel
    {
    /// <summary>
    /// A control panel that displays the administrator menu to those users who are
    /// authorized to view (at least) that page.  No additional page or module 
    /// functionality is exposed.
    /// </summary>
    public partial class AdminMenuControlPanel : ControlPanelBase
        {
        /// <summary>
        /// Retreives the page name of the administrator menu
        /// </summary>
        private static string AdminTabName
            { get { return Localization.GetString("//Admin.String", Localization.GlobalResourceFile).Replace("[L]", string.Empty).Trim(); } }

        protected override void OnInit(EventArgs e)
            {
            base.OnInit(e);

            // Only display this control panel if the user is authorized to 
            // view at least the root administrator page.
            ControlPanel.Visible = TabPermissionController.CanViewPage(new TabController().GetTabByName(AdminTabName, PortalSettings.PortalId));

            // If we are going to be presenting anything, do some work.
            if (ControlPanel.Visible)
                {
                ClientResourceManager.RegisterStyleSheet(Page, "~/admin/ControlPanel/module.css");
                jQuery.RequestHoverIntentRegistration();
                ClientResourceManager.RegisterScript(Page, "~/Resources/ControlPanel/ControlPanel.debug.js");
                }
            }

        /// <summary>
        /// Make sure our menu is configured to include the admin page hierarchy
        /// </summary>
        protected virtual void DetermineNodesToInclude(object sender, EventArgs e)
            { ((DotNetNuke.Web.DDRMenu.SkinObject)sender).IncludeNodes = AdminTabName; }
        }
    }